//
//  VisitorView.swift
//  ZHTQWeibo
//
//  Created by ZHTQ on 2018/9/14.
//  Copyright © 2018年 ZHTQ. All rights reserved.
//

import UIKit

//protocol VisitViewDelegate: NSObjectProtocol {
//    func visitorViewDidRegisterButton(visiterView: VisitorView)
//    func visitorViewDidLoginButton(visiterView: VisitorView)
//}

class VisitorView: UIView {
    ///旋转动画的image 除主页显示 其他隐藏状态
    @IBOutlet weak var rotationImageView: UIImageView!
    ///覆盖层的miage 除主页显示 其他隐藏状态
    @IBOutlet weak var coverImageView: UIImageView!
    ///图标 不同页面转换
    @IBOutlet weak var iconImageView: UIImageView!
    ///文字介绍类容
    @IBOutlet weak var titleLabel: UILabel!
    ///注册按钮
    @IBOutlet weak var registerButtion: UIButton!
    ///登录按钮
    @IBOutlet weak var logionButton: UIButton!
    

    
    //MARK: - 外部控制方法
    ///通过xibchuangjianview
    class func visitorView() -> VisitorView {
        return Bundle.main.loadNibNamed("VisitorView", owner: nil, options: nil)?.last as! VisitorView
    }
    
    ///设置显示信息
    func setupVisitorInfo(_ iconimageName: String?, title: String){
        
        //设置显示文字
        titleLabel.text = title
        guard let iconName = iconimageName else {
            
            return
        }
        //隐藏不需要显示的图片
        rotationImageView.isHidden = true
        coverImageView.isHidden = true
        //设置icon图片
        iconImageView.image = UIImage(named: iconName)
    }
    
    ///给旋转图片的设置动画
    func startRotationImageViewAnimation() {
        
        //创建核心动画
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        //设置核心动画时间
        anim.toValue = 2 * Double.pi
        anim.duration = 8.0
        anim.repeatCount = MAXFLOAT
        //让动画在试图销毁前不停止
        anim.isRemovedOnCompletion = false
        
        //给空间添加动画
        rotationImageView.layer.add(anim, forKey: nil)
        
    }
    
}
